﻿using Anke.SHManage.BLL;
using Anke.SHManage.BLL.FixedAssets;
using Anke.SHManage.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Anke.SHManage.Web.Areas.FixedAssets.Controllers
{
    public class FixedAssetsClassController : Controller
    {
        //固定资产分类维护
        // GET: /FixedAssets/FixedAssetsClass/

        /// <summary>
        /// 固定资产分类维护页面
        /// </summary>
        /// <returns></returns>
        public ActionResult AssetsClass()
        {
            //2019-10-31 plq 固定资产分类维护新增、修改、启/禁用权限配置
            //获取用户最大统计权限
            E_StatisticsPermisson em = UserOperateContext.Current.getMaxPerForStatistics();
            this.ViewData["em"] = em;
            UserOperateContext userOperateContext = new UserOperateContext();
            bool Insert = userOperateContext.getGongneng((int)E_FixedAssetsPermission.固定资产分类新增修改);//判断登录人有无“新增修改”资产分类权限
            if (Insert)
            {
                this.ViewData["RolePermissionInsert"] = "Insert";//登录人有新增修改资产分类权限
            }
            bool Delete = UserOperateContext.Current.getGongneng((int)E_FixedAssetsPermission.固定资产分类启禁用);//判断登录人有无“启禁用”资产分类权限
            if (Delete)
            {
                this.ViewData["RolePermissionDelete"] = "Delete";//登录人有“启禁用”资产分类权限
            }
            return View("AssetsClass");
        }


        /// <summary>
        /// 新增固定资产分类
        /// </summary>
        /// <returns></returns>
        public ActionResult SaveAssetsType()
        {
            //2019-09-18 plq 新增物资分类
            string PID = Request.Form["PID"].ToString(); //父级编码
            string mName = Request.Form["MTypeName"].ToString(); //分类名
            FixedAssetsClassBLL bll = new FixedAssetsClassBLL();
            if (bll.SaveAssetsType(PID, mName))
            {
                return Json(new { Result = "OK", Message = "新增资产分类成功！" }, "text/plain;charset=UTF-8", JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(new { Result = "Error", Message = "新增资产分类失败！" }, "text/plain;charset=UTF-8", JsonRequestBehavior.AllowGet);
            }

        }

        /// <summary>
        /// 修改物资分类名称
        /// </summary>
        /// <returns></returns>
        public ActionResult EditAssetsType()
        {
            string MID = Request.Form["MID"].ToString(); //分类编码
            string mName = Request.Form["MTypeName"].ToString(); //分类名称
            FixedAssetsClassBLL bll = new FixedAssetsClassBLL();
            if (bll.EditAssetsType(MID, mName))
            {
                return Json(new { Result = "OK", Message = "修改资产分类名称成功！" }, "text/plain;charset=UTF-8", JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(new { Result = "Error", Message = "修改资产分类名称失败！" }, "text/plain;charset=UTF-8", JsonRequestBehavior.AllowGet);
            }

        }

        /// <summary>
        /// 禁用物资分类
        /// </summary>
        /// <returns></returns>
        public ActionResult DisableAssetsType()
        {
            string MID = Request.Form["MID"].ToString();
            FixedAssetsClassBLL bll = new FixedAssetsClassBLL();
            if (bll.DisableAssetsType(MID))
            {
                return Json(new { Result = "OK", Message = "禁用资产分类成功！" }, "text/plain;charset=UTF-8", JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(new { Result = "Error", Message = "禁用资产分类失败！" }, "text/plain;charset=UTF-8", JsonRequestBehavior.AllowGet);
            }

        }

        /// <summary>
        /// 启用物资分类
        /// </summary>
        /// <returns></returns>
        public ActionResult EnableMaterialType()
        {
            string MID = Request.Form["MID"].ToString();
            FixedAssetsClassBLL bll = new FixedAssetsClassBLL();
            if (bll.EnableAssetsType(MID))
            {
                return Json(new { Result = "OK", Message = "启用资产分类成功！" }, "text/plain;charset=UTF-8", JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(new { Result = "Error", Message = "启用资产分类失败！" }, "text/plain;charset=UTF-8", JsonRequestBehavior.AllowGet);
            }

        }


    }
}
